<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="prev" href="module-functools.html" />
<link rel="parent" href="numeric.html" />
<link rel="next" href="operator-map.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>6.7 operator -- Standard operators as functions.</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.6.1 partial Objects"
  href="partial-objects.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="6. numeric and Mathematical"
  href="numeric.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="6.7.1 mapping Operators to"
  href="operator-map.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="partial-objects.html">6.6.1 partial Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="numeric.html">6. Numeric and Mathematical</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="operator-map.html">6.7.1 Mapping Operators to</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION008700000000000000000">
6.7 <tt class="module">operator</tt> --
         Standard operators as functions.</a>
</h1>
<a name="module-operator"></a>

<p>

<p>
The <tt class="module">operator</tt> module exports a set of functions implemented in C
corresponding to the intrinsic operators of Python.  For example,
<code>operator.add(x, y)</code> is equivalent to the expression <code>x+y</code>.  The
function names are those used for special class methods; variants without
leading and trailing "<tt class="samp">__</tt>" are also provided for convenience.

<p>
The functions fall into categories that perform object comparisons,
logical operations, mathematical operations, sequence operations, and
abstract type tests.

<p>
The object comparison functions are useful for all objects, and are
named after the rich comparison operators they support:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1082' xml:id='l2h-1082' class="function">lt</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">le</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">eq</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">ne</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">ge</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">gt</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__lt__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__le__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__eq__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__ne__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__ge__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__gt__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Perform ``rich comparisons'' between <var>a</var> and <var>b</var>. Specifically,
<code>lt(<var>a</var>, <var>b</var>)</code> is equivalent to <code><var>a</var> &lt; <var>b</var></code>,
<code>le(<var>a</var>, <var>b</var>)</code> is equivalent to <code><var>a</var> &lt;= <var>b</var></code>,
<code>eq(<var>a</var>, <var>b</var>)</code> is equivalent to <code><var>a</var> == <var>b</var></code>,
<code>ne(<var>a</var>, <var>b</var>)</code> is equivalent to <code><var>a</var> != <var>b</var></code>,
<code>gt(<var>a</var>, <var>b</var>)</code> is equivalent to <code><var>a</var> &gt; <var>b</var></code>
and
<code>ge(<var>a</var>, <var>b</var>)</code> is equivalent to <code><var>a</var> &gt;= <var>b</var></code>.
Note that unlike the built-in <tt class="function">cmp()</tt>, these functions can
return any value, which may or may not be interpretable as a Boolean
value.  See the <em class="citetitle"><a
 href="../ref/ref.html"
 title="Python Reference Manual"
 >Python Reference Manual</a></em>
for more information about rich comparisons.

<span class="versionnote">New in version 2.2.</span>

</dl>

<p>
The logical operations are also generally applicable to all objects,
and support truth tests, identity tests, and boolean operations:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1094' xml:id='l2h-1094' class="function">not_</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__not__</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>Return the outcome of <tt class="keyword">not</tt> <var>o</var>.  (Note that there is no
<tt class="method">__not__()</tt> method for object instances; only the interpreter
core defines this operation.  The result is affected by the
<tt class="method">__nonzero__()</tt> and <tt class="method">__len__()</tt> methods.)
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1096' xml:id='l2h-1096' class="function">truth</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
Return <tt class="constant">True</tt> if <var>o</var> is true, and <tt class="constant">False</tt>
otherwise.  This is equivalent to using the <tt class="class">bool</tt>
constructor.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1097' xml:id='l2h-1097' class="function">is_</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
Return <code><var>a</var> is <var>b</var></code>.  Tests object identity.

<span class="versionnote">New in version 2.3.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1098' xml:id='l2h-1098' class="function">is_not</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
Return <code><var>a</var> is not <var>b</var></code>.  Tests object identity.

<span class="versionnote">New in version 2.3.</span>

</dl>

<p>
The mathematical and bitwise operations are the most numerous:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1099' xml:id='l2h-1099' class="function">abs</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__abs__</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>Return the absolute value of <var>o</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1101' xml:id='l2h-1101' class="function">add</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__add__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>+</code> <var>b</var>, for <var>a</var> and <var>b</var> numbers.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1103' xml:id='l2h-1103' class="function">and_</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__and__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return the bitwise and of <var>a</var> and <var>b</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1105' xml:id='l2h-1105' class="function">div</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__div__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>/</code> <var>b</var> when <code>__future__.division</code> is not
in effect.  This is also known as ``classic'' division.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1107' xml:id='l2h-1107' class="function">floordiv</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__floordiv__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>//</code> <var>b</var>.

<span class="versionnote">New in version 2.2.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1109' xml:id='l2h-1109' class="function">inv</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">invert</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__inv__</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__invert__</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>Return the bitwise inverse of the number <var>o</var>.  This is equivalent
to <code>~</code><var>o</var>.  The names <tt class="function">invert()</tt> and
<tt class="function">__invert__()</tt> were added in Python 2.0.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1113' xml:id='l2h-1113' class="function">lshift</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__lshift__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> shifted left by <var>b</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1115' xml:id='l2h-1115' class="function">mod</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__mod__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>%</code> <var>b</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1117' xml:id='l2h-1117' class="function">mul</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__mul__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>*</code> <var>b</var>, for <var>a</var> and <var>b</var> numbers.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1119' xml:id='l2h-1119' class="function">neg</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__neg__</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>Return <var>o</var> negated.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1121' xml:id='l2h-1121' class="function">or_</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__or__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return the bitwise or of <var>a</var> and <var>b</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1123' xml:id='l2h-1123' class="function">pos</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__pos__</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>Return <var>o</var> positive.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1125' xml:id='l2h-1125' class="function">pow</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__pow__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>**</code> <var>b</var>, for <var>a</var> and <var>b</var> numbers.

<span class="versionnote">New in version 2.3.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1127' xml:id='l2h-1127' class="function">rshift</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__rshift__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> shifted right by <var>b</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1129' xml:id='l2h-1129' class="function">sub</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__sub__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>-</code> <var>b</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1131' xml:id='l2h-1131' class="function">truediv</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__truediv__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>/</code> <var>b</var> when <code>__future__.division</code> is in
effect.  This is also known as ``true'' division.

<span class="versionnote">New in version 2.2.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1133' xml:id='l2h-1133' class="function">xor</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__xor__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return the bitwise exclusive or of <var>a</var> and <var>b</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1135' xml:id='l2h-1135' class="function">index</tt></b>(</nobr></td>
  <td><var>a</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__index__</tt></b>(</nobr></td>
  <td><var>a</var>)</td></tr></table></dt>
<dd>Return <var>a</var> converted to an integer.  Equivalent to <var>a</var><code>.__index__()</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
Operations which work with sequences include:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1137' xml:id='l2h-1137' class="function">concat</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__concat__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>+</code> <var>b</var> for <var>a</var> and <var>b</var> sequences.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1139' xml:id='l2h-1139' class="function">contains</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__contains__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return the outcome of the test <var>b</var> <code>in</code> <var>a</var>.
Note the reversed operands.  The name <tt class="function">__contains__()</tt> was
added in Python 2.0.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1141' xml:id='l2h-1141' class="function">countOf</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
Return the number of occurrences of <var>b</var> in <var>a</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1142' xml:id='l2h-1142' class="function">delitem</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__delitem__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Remove the value of <var>a</var> at index <var>b</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1144' xml:id='l2h-1144' class="function">delslice</tt></b>(</nobr></td>
  <td><var>a, b, c</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__delslice__</tt></b>(</nobr></td>
  <td><var>a, b, c</var>)</td></tr></table></dt>
<dd>Delete the slice of <var>a</var> from index <var>b</var> to index <var>c</var><code>-1</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1146' xml:id='l2h-1146' class="function">getitem</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__getitem__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return the value of <var>a</var> at index <var>b</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1148' xml:id='l2h-1148' class="function">getslice</tt></b>(</nobr></td>
  <td><var>a, b, c</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__getslice__</tt></b>(</nobr></td>
  <td><var>a, b, c</var>)</td></tr></table></dt>
<dd>Return the slice of <var>a</var> from index <var>b</var> to index <var>c</var><code>-1</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1150' xml:id='l2h-1150' class="function">indexOf</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
Return the index of the first of occurrence of <var>b</var> in <var>a</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1151' xml:id='l2h-1151' class="function">repeat</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__repeat__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>Return <var>a</var> <code>*</code> <var>b</var> where <var>a</var> is a sequence and
<var>b</var> is an integer.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1153' xml:id='l2h-1153' class="function">sequenceIncludes</tt></b>(</nobr></td>
  <td><var>...</var>)</td></tr></table></dt>
<dd>
<div class="versionnote"><b>Deprecated since release 2.0.</b>
Use <tt class="function">contains()</tt> instead.</div><p></p>
Alias for <tt class="function">contains()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1154' xml:id='l2h-1154' class="function">setitem</tt></b>(</nobr></td>
  <td><var>a, b, c</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__setitem__</tt></b>(</nobr></td>
  <td><var>a, b, c</var>)</td></tr></table></dt>
<dd>Set the value of <var>a</var> at index <var>b</var> to <var>c</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1156' xml:id='l2h-1156' class="function">setslice</tt></b>(</nobr></td>
  <td><var>a, b, c, v</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__setslice__</tt></b>(</nobr></td>
  <td><var>a, b, c, v</var>)</td></tr></table></dt>
<dd>Set the slice of <var>a</var> from index <var>b</var> to index <var>c</var><code>-1</code> to the
sequence <var>v</var>.
</dl>

<p>
Many operations have an ``in-place'' version.  The following functions
provide a more primitive access to in-place operators than the usual
syntax does; for example, the statement <code>x += y</code> is equivalent to
<code>x = operator.iadd(x, y)</code>.  Another way to put it is to say that
<code>z = operator.iadd(x, y)</code> is equivalent to the compound statement
<code>z = x; z += y</code>.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1158' xml:id='l2h-1158' class="function">iadd</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__iadd__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = iadd(a, b)</code> is equivalent to <code>a += b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1160' xml:id='l2h-1160' class="function">iand</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__iand__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = iand(a, b)</code> is equivalent to <code>a &amp;= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1162' xml:id='l2h-1162' class="function">iconcat</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__iconcat__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = iconcat(a, b)</code> is equivalent to <code>a += b</code> for <var>a</var>
and <var>b</var> sequences.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1164' xml:id='l2h-1164' class="function">idiv</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__idiv__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = idiv(a, b)</code> is equivalent to <code>a /= b</code> when
<code>__future__.division</code> is not in effect.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1166' xml:id='l2h-1166' class="function">ifloordiv</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__ifloordiv__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = ifloordiv(a, b)</code> is equivalent to <code>a //= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1168' xml:id='l2h-1168' class="function">ilshift</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__ilshift__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = ilshift(a, b)</code> is equivalent to <code>a &lt;</code><code>&lt;= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1170' xml:id='l2h-1170' class="function">imod</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__imod__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = imod(a, b)</code> is equivalent to <code>a %= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1172' xml:id='l2h-1172' class="function">imul</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__imul__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = imul(a, b)</code> is equivalent to <code>a *= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1174' xml:id='l2h-1174' class="function">ior</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__ior__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = ior(a, b)</code> is equivalent to <code>a |= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1176' xml:id='l2h-1176' class="function">ipow</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__ipow__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = ipow(a, b)</code> is equivalent to <code>a **= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1178' xml:id='l2h-1178' class="function">irepeat</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__irepeat__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = irepeat(a, b)</code> is equivalent to <code>a *= b</code> where
<var>a</var> is a sequence and <var>b</var> is an integer.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1180' xml:id='l2h-1180' class="function">irshift</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__irshift__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = irshift(a, b)</code> is equivalent to <code>a &gt;&gt;= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1182' xml:id='l2h-1182' class="function">isub</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__isub__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = isub(a, b)</code> is equivalent to <code>a -= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1184' xml:id='l2h-1184' class="function">itruediv</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__itruediv__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = itruediv(a, b)</code> is equivalent to <code>a /= b</code> when
<code>__future__.division</code> is in effect.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1186' xml:id='l2h-1186' class="function">ixor</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd>
<dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt class="function">__ixor__</tt></b>(</nobr></td>
  <td><var>a, b</var>)</td></tr></table></dt>
<dd><code>a = ixor(a, b)</code> is equivalent to <code>a ^= b</code>.

<span class="versionnote">New in version 2.5.</span>

</dl>

<p>
The <tt class="module">operator</tt> module also defines a few predicates to test the
type of objects.  <span class="note"><b class="label">Note:</b>
Be careful not to misinterpret the
results of these functions; only <tt class="function">isCallable()</tt> has any
measure of reliability with instance objects.  For example:</span>

<p>
<div class="verbatim"><pre>
&gt;&gt;&gt; class C:
...     pass
... 
&gt;&gt;&gt; import operator
&gt;&gt;&gt; o = C()
&gt;&gt;&gt; operator.isMappingType(o)
True
</pre></div>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1188' xml:id='l2h-1188' class="function">isCallable</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
<div class="versionnote"><b>Deprecated since release 2.0.</b>
Use the <tt class="function">callable()</tt> built-in function instead.</div><p></p>
Returns true if the object <var>o</var> can be called like a function,
otherwise it returns false.  True is returned for functions, bound and
unbound methods, class objects, and instance objects which support the
<tt class="method">__call__()</tt> method.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1189' xml:id='l2h-1189' class="function">isMappingType</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
Returns true if the object <var>o</var> supports the mapping interface.
This is true for dictionaries and all instance objects defining
<tt class="method">__getitem__</tt>.
<span class="warning"><b class="label">Warning:</b>
There is no reliable way to test if an instance
supports the complete mapping protocol since the interface itself is
ill-defined.  This makes this test less useful than it otherwise might
be.</span>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1190' xml:id='l2h-1190' class="function">isNumberType</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
Returns true if the object <var>o</var> represents a number.  This is true
for all numeric types implemented in C.
<span class="warning"><b class="label">Warning:</b>
There is no reliable way to test if an instance
supports the complete numeric interface since the interface itself is
ill-defined.  This makes this test less useful than it otherwise might
be.</span>
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1191' xml:id='l2h-1191' class="function">isSequenceType</tt></b>(</nobr></td>
  <td><var>o</var>)</td></tr></table></dt>
<dd>
Returns true if the object <var>o</var> supports the sequence protocol.
This returns true for all objects which define sequence methods in C,
and for all instance objects defining <tt class="method">__getitem__</tt>.
<span class="warning"><b class="label">Warning:</b>
There is no reliable
way to test if an instance supports the complete sequence interface
since the interface itself is ill-defined.  This makes this test less
useful than it otherwise might be.</span>
</dl>

<p>
Example: Build a dictionary that maps the ordinals from <code>0</code> to
<code>255</code> to their character equivalents.

<p>
<div class="verbatim"><pre>
&gt;&gt;&gt; import operator
&gt;&gt;&gt; d = {}
&gt;&gt;&gt; keys = range(256)
&gt;&gt;&gt; vals = map(chr, keys)
&gt;&gt;&gt; map(operator.setitem, [d]*len(keys), keys, vals)
</pre></div>

<p>
The <tt class="module">operator</tt> module also defines tools for generalized attribute
and item lookups.  These are useful for making fast field extractors
as arguments for <tt class="function">map()</tt>, <tt class="function">sorted()</tt>,
<tt class="method">itertools.groupby()</tt>, or other functions that expect a
function argument.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1192' xml:id='l2h-1192' class="function">attrgetter</tt></b>(</nobr></td>
  <td><var>attr</var><big>[</big><var>, args...</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a callable object that fetches <var>attr</var> from its operand.
If more than one attribute is requested, returns a tuple of attributes.
After, "<tt class="samp">f=attrgetter('name')</tt>", the call "<tt class="samp">f(b)</tt>" returns
"<tt class="samp">b.name</tt>".  After, "<tt class="samp">f=attrgetter('name', 'date')</tt>", the call
"<tt class="samp">f(b)</tt>" returns "<tt class="samp">(b.name, b.date)</tt>". 

<span class="versionnote">New in version 2.4.</span>

<span class="versionnote">Changed in version 2.5:
Added support for multiple attributes.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-1193' xml:id='l2h-1193' class="function">itemgetter</tt></b>(</nobr></td>
  <td><var>item</var><big>[</big><var>, args...</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Return a callable object that fetches <var>item</var> from its operand.
If more than one item is requested, returns a tuple of items.
After, "<tt class="samp">f=itemgetter(2)</tt>", the call "<tt class="samp">f(b)</tt>" returns
"<tt class="samp">b[2]</tt>".
After, "<tt class="samp">f=itemgetter(2,5,3)</tt>", the call "<tt class="samp">f(b)</tt>" returns
"<tt class="samp">(b[2], b[5], b[3])</tt>".		

<span class="versionnote">New in version 2.4.</span>

<span class="versionnote">Changed in version 2.5:
Added support for multiple item extraction.</span>
		
</dl>

<p>
Examples:

<p>
<div class="verbatim"><pre>
&gt;&gt;&gt; from operator import itemgetter
&gt;&gt;&gt; inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
&gt;&gt;&gt; getcount = itemgetter(1)
&gt;&gt;&gt; map(getcount, inventory)
[3, 2, 5, 1]
&gt;&gt;&gt; sorted(inventory, key=getcount)
[('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
</pre></div>

<p>

<p><br /></p><hr class='online-navigation' />
<div class='online-navigation'>
<!--Table of Child-Links-->
<a name="CHILD_LINKS"><strong>Subsections</strong></a>

<ul class="ChildLinks">
<li><a href="operator-map.html">6.7.1 Mapping Operators to Functions</a>
</ul>
<!--End of Table of Child-Links-->
</div>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="6.6.1 partial Objects"
  href="partial-objects.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="6. numeric and Mathematical"
  href="numeric.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="6.7.1 mapping Operators to"
  href="operator-map.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="partial-objects.html">6.6.1 partial Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="numeric.html">6. Numeric and Mathematical</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="operator-map.html">6.7.1 Mapping Operators to</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
